package com.airlines.crewassignment.service.crewlocation.impl;

import com.airlines.common.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.airlines.crewassignment.service.crewlocation.DutyScheduleService;
import com.airlines.crewassignment.entity.crewlocation.DutySchedule;
import java.util.List;
import com.airlines.crewassignment.dao.crewlocation.DutyScheduleMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author xxxx
 * @date 2018/07/02 16:17:14
 * @company xxxx Airlines
 * @description 
 */
@Service
public class DutyScheduleServiceImpl implements DutyScheduleService {

    @Autowired
    private DutyScheduleMapper dutyScheduleMapper;

    @Override
    public int insert(DutySchedule dutySchedule){
        return dutyScheduleMapper.insert(dutySchedule);
    }

    @Override
    public int delete(DutySchedule dutySchedule){
        return dutyScheduleMapper.delete(dutySchedule);
    }


    @Override
    @Transactional
    public int update(DutySchedule oldDutySchedule,DutySchedule dutySchedule){
        dutyScheduleMapper.delete(oldDutySchedule);
        return dutyScheduleMapper.insert(dutySchedule);
    }

    @Override
    public DutySchedule get(DutySchedule dutySchedule){
        return dutyScheduleMapper.get(dutySchedule);
    }

    @Override
    public List<DutySchedule> list(DutySchedule dutySchedule){
        return dutyScheduleMapper.list(dutySchedule);
    }

    @Override
    public Page list(DutySchedule dutySchedule, Page page){
        PageHelper.startPage(page.getPageNumber(), page.getPageSize());
        List<DutySchedule> list = dutyScheduleMapper.listByFuzzy(dutySchedule);
        PageInfo<DutySchedule> pageInfo = new PageInfo<DutySchedule>(list);
        page.setTotal(String.valueOf(pageInfo.getTotal()));
        page.setRows(pageInfo.getList());
        return page;
    }




}
